package team.knowers.tourist.controller;

import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import team.knowers.tourist.common.convention.result.Result;
import team.knowers.tourist.common.convention.result.Results;
import team.knowers.tourist.dao.entity.PaymentDO;
import team.knowers.tourist.dto.req.PaymentCreateReqDTO;
import team.knowers.tourist.service.PaymentService;

import java.util.List;

@RestController
@RequiredArgsConstructor
public class PaymentController {
    private final PaymentService paymentService;
    /**
     * 创建订单
     * @param req
     */
    @PutMapping("/api/tourist/createPayment")
    public Result<Void> createPayment (@RequestBody PaymentCreateReqDTO req)
    {
        paymentService.createPayment(req);
        return Results.success();
    }
    /**
     * 取消订单
     * @param id
     */
    @PostMapping("/api/tourist/cancelPayment")
    public Result<Void> cancelPayment(@RequestParam int id)
    {
        paymentService.cancelPayment(id);
        return Results.success();
    }
    /**
     * 支付订单
     */
    @PostMapping("/api/tourist/payPayment")
    public Result<Void> payPayment(@RequestParam int id){
        paymentService.payPayment(id);
        return Results.success();
    }
    @GetMapping("/api/tourist/viewOrder/{touristId}")
    public Result<List<PaymentDO>> viewOrder(@PathVariable int touristId)
    {
        return Results.success(paymentService.viewOrder(touristId));
    }
    @GetMapping("/api/tourist/getTicket")
    public Result<Boolean> getTicket(@RequestParam("touristId") int touristId,
                                     @RequestParam("bookingHash") int bookingHash,
                                     @RequestParam("paymentHash") int paymentHash){
        return Results.success(paymentService.getTicket(touristId, bookingHash, paymentHash));
    }

}
